<?
if($_POST['md_id'] >= 1)
{
	$valuearray['md_name'] = $_POST['name1'];
	$valuearray['md_name2'] = $_POST['name2'];
	$valuearray['md_color'] = $_POST['colors'];
	$valuearray['md_ip'] = $_SERVER['REMOTE_ADDR'];	
	$valuearray['md_function']='';
	if($_POST['function1'])  foreach($_POST['function1'] as $ft) $valuearray['md_function'] .= $ft."|";
	$valuearray['md_function'] .= "timce|";
	Qupdate("module","",$valuearray," md_id = ".$_POST['md_id']);
}
else if($_POST)
{
	$maxorder = Q1(" select MAX(md_order) from module ");
	$valuearray['md_name'] = $_POST['name1'];
	$valuearray['md_name2'] = $_POST['name2'];
	$valuearray['md_color'] = $_POST['colors'];
	$valuearray['md_order'] = $maxorder[0]+1;
	$valuearray['md_ip'] = $_SERVER['REMOTE_ADDR'];	
	$valuearray['md_function']='';
	if($_POST['function1'])  foreach($_POST['function1'] as $ft) $valuearray['md_function'] .= $ft."|";
	
	Qinsert("module","",$valuearray);
}
else if($_REQUEST['swap1'] >= 1 && $_REQUEST['swap2'] >= 1)
{
		$r1 = Q1("select md_id,md_order from module  where md_id =   ".$_REQUEST['swap1']);
		$r2 = Q1("select md_id,md_order from module  where md_id =   ".$_REQUEST['swap2']);
		mysql_query("update module set md_order = '".$r2['md_order']."' where md_id = '".$r1['md_id']."'  ");
		mysql_query("update module set md_order = '".$r1['md_order']."' where md_id = '".$r2['md_id']."'  ");
}
else if($_REQUEST['delid'] >= 1) 
{
	mysql_query("DELETE FROM `module` WHERE `module`.`md_id` = '".$_REQUEST['delid']."' LIMIT 1");
}
?>


<?
if($_REQUEST['md_id'] >= 1) $r = Q1("select * from module where md_id = ".$_REQUEST['md_id']);

$rx = Q1("select * from language limit 1");
?>
<script src="js/301a.js" type="text/javascript"></script>
<div id="colorpicker301" class="colorpicker301"></div>
<p>
    <form action="" method="post" name="tcptest">



    <fieldset>
    <legend>เพิ่มเมนูด้านบนเว็บไซต์</legend>
    
    
    
        <label>ตั้งชื่อเมนูด้านบน</label><br>
		
		<?=$rx[lang1]?> <br><input name="name1" type="text" value="<?=$r['md_name']?>" /><br><BR>
		<?=$rx[lang2]?> <br><input name="name2" type="text" value="<?=$r['md_name2']?>" /><br>
        
        
        <!--
		<label>Color:</label><A HREF="#" onclick="showColorGrid3('color_1','none');return false;"><img src="images/sel.gif"></A>&nbsp;&nbsp;<input type="text" ID="color_1" size="9" value="<?=$r['md_color']?>" name="colors">
        -->
        
        
        <label>กำหนดลักษณะเนื้อหาของเมนู</label>
        <?
        $function1 = array("อัลบั้มภาพ","แบบฟอร์มติดต่อเรา","แผนที่","บทความ");
        foreach($function1 as $ft)
        {
        ?>
    <div style="width:200px;">
    <input name="function1[]" type="checkbox" value="<?=$ft?>" <?=selected($ft,$r['md_function'],0)?> />
    <?=$ft?>
    </div>
        <?
        }
        ?>
    <br />
<br />

    <input name="" type="submit" value="<?=btsubmit($r['md_id'])?>"  />
    
    
    
    </fieldset>
    <input name="md_id" type="hidden" value="<?=$r['md_id']?>" />
    
    </form>

</p>

<p>
<?
$k=0;
$r1 = Q2("select * from module order by md_order desc");
foreach($r1 as $r) {$orderingg[] = $r['md_id'];}
foreach($r1 as $r)
{
?>
<div>	[&nbsp;
        <? if($orderingg[($k-1)] > 0) { ?>
        <a href="?body=module&page=<?=$_REQUEST['page']?>&swap1=<?=$orderingg[$k]?>&swap2=<?=($orderingg[($k-1)])?>"><img src="images/uparrow.png" width="10" height="10" alt="Move up" title="เลื่อนไปตำแหน่งก่อนหน้า"  <?=btswap()?> border="0" ></a> 					
		<? } ?>
        
        <? if($orderingg[($k+1)] > 0) { ?>
        <a href="?body=module&page=<?=$_REQUEST['page']?>&swap1=<?=$orderingg[$k]?>&swap2=<?=($orderingg[($k+1)])?>"><img src="images/downarrow.png" width="10" height="10" alt="Move down" title="เลื่อนไปตำแหน่งถัดไป"  <?=btswap()?> border="0" ></a>
		<? } ?>&nbsp;]
        
        &nbsp;<a href="?body=module&md_id=<?=$r['md_id']?>"><img src="images/addedit.png" width="15" height="15" alt="Edit" title="แก้ไขเมนู"  <?=btswap()?> border="0" ></a>&nbsp;
        <a href="?body=module&md_id=<?=$r['md_id']?>&page=<?=$_REQUEST['page']?>&delid=<?=$r['md_id']?>"  onclick="javascript:if(confirm('Are you sure you want to delete')){return true;} else{return false;}" > <img src="images/cancel_f2.png" alt="Delete" title="ลบเมนู"  width="15" height="15" border="0" <?=btswap()?> > </a>
&nbsp;::::: <?=$r['md_name']?> / <?=$r['md_name2']?>&nbsp;
		
</div>
<?
$k++;
}
?>
</p>